package main

import "fmt"

type Hero struct {
	No    int
	Name  string
	Left  *Hero
	Right *Hero
}

//前序遍历（先遍历最顶部的父节点->然后遍历左边树->再遍历右边树）
func prePrint(node *Hero) {
	if node != nil {
		fmt.Printf("no=%d name=%s \n", node.No, node.Name)
		//输出左边的
		prePrint(node.Left)
		//输出右边的
		prePrint(node.Right)
	}
}

//中序遍历(->先输出root节点的左边 -> 再输出中间节点 ->再输出右边节点)
func cententPrint(node *Hero) {
	if node != nil {
		cententPrint(node.Left)
		fmt.Printf("no=%d name=%s \n", node.No, node.Name)
		cententPrint(node.Right)
	}
}

//后序遍历(->先输出root节点的左边 -> 再输出右边节点->再输出中间节点 )
func nextPrint(node *Hero) {
	if node != nil {
		cententPrint(node.Left)
		cententPrint(node.Right)
		fmt.Printf("no=%d name=%s \n", node.No, node.Name)
	}
}

func main() {
	root := Hero{
		No:   1,
		Name: "宋江",
	}

	left1 := Hero{
		No:   2,
		Name: "吴用",
	}

	left10 := Hero{
		No:   21,
		Name: "left1 21",
	}

	right10 := Hero{
		No:   22,
		Name: "right 22",
	}

	left1.Left = &left10
	left1.Right = &right10

	right1 := Hero{
		No:   3,
		Name: "卢俊义",
	}

	right2 := Hero{
		No:   4,
		Name: "林冲",
	}

	root.Left = &left1
	root.Right = &right1
	right1.Right = &right2
	//prePrint(&root)
	//cententPrint(&root)
	nextPrint(&root);
}
